package com.ctshk.sapp.finance.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.rpc.finance.dto.bill.BillCheckDetailDTO;
import com.ctshk.rpc.finance.dto.bill.BillCheckDetailListDTO;
import com.ctshk.rpc.finance.dto.bill.BillCheckListDTO;
import com.ctshk.rpc.finance.dto.bill.BillListDTO;
import com.ctshk.rpc.finance.req.bill.*;
import com.ctshk.rpc.finance.service.IFinanceBillCheckService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.ctshk.common.web.support.BaseController;

import javax.validation.Valid;

/**
 * <p>
 * 客户对账 前端控制器
 * </p>
 *
 * @author 叶冠峰
 * @since 2021-03-26
 */
@RestController
@Api(value = "客户对账", tags = "客户对账")
@RequestMapping("/finance-bill-check")
public class FinanceBillCheckController extends BaseController {

    @DubboReference
    private IFinanceBillCheckService billCheckService;

    @ApiOperation(value = "列表", notes = "列表（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.QUERY, operTitle = "对账单列表", operDesc = "对账单列表列表")
    @PostMapping("/list")
    public Result<PageResponse<BillCheckListDTO>> list(@RequestBody BillCheckListReq req) {
        return billCheckService.list(req);
    }

    @ApiOperation(value = "新增", notes = "新增（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.ADD, operTitle = "新增对账单", operDesc = "新增对账单")
    @PostMapping("/add")
    public Result add(@RequestBody @Valid BillCheckAddReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return billCheckService.add(req);
    }

    @ApiOperation(value = "批量删除", notes = "批量删除（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.DELETE, operTitle = "批量删除对账单", operDesc = "批量删除对账单")
    @PostMapping("/del")
    public Result del(@RequestBody @Valid BillCheckDelReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return billCheckService.del(req);
    }

    @ApiOperation(value = "详情", notes = "详情（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.QUERY, operTitle = "对账单详情", operDesc = "对账单详情")
    @PostMapping("/detail")
    public Result<BillCheckDetailDTO> detail(@RequestBody @Valid BillCheckDetailReq req) {
        return billCheckService.detail(req);
    }

    @ApiOperation(value = "修改", notes = "修改（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.UPDATE, operTitle = "修改对账单", operDesc = "修改对账单")
    @PostMapping("/update")
    public Result update(@RequestBody @Valid BillCheckUpdateReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return billCheckService.update(req);
    }

    @ApiOperation(value = "审批", notes = "审批（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.UPDATE, operTitle = "对账单审批", operDesc = "对账单审批")
    @PostMapping("/approval")
    public Result approval(@RequestBody @Valid BillCheckApprovalReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return billCheckService.approval(req);
    }

    @ApiOperation(value = "往来明细列表", notes = "往来明细列表（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.QUERY, operTitle = "往来明细列表", operDesc = "往来明细列表")
    @PostMapping("/detail-list")
    public Result<PageResponse<BillCheckDetailListDTO>> detailList(@RequestBody BillCheckDetailListReq req) {
        return billCheckService.detailList(req);
    }

    @ApiOperation(value = "对账单详情-对账明细列表", notes = "对账单详情-对账明细列表（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.QUERY, operTitle = "对账单详情-对账明细列表", operDesc = "对账单详情-对账明细列表")
    @PostMapping("/check-detail-list")
    public Result<PageResponse<BillCheckDetailListDTO>> checkDetailList(@RequestBody @Valid BillCheckIdDetailListReq req) {
        return billCheckService.checkDetailList(req);
    }

    @ApiOperation(value = "撤回审批", notes = "撤回审批（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.FINANCE, operType = OperationLogType.UPDATE, operTitle = "撤回申请预收款审批", operDesc = "撤回申请预收款审批")
    @PostMapping("/roll-back")
    public Result rollBack(@RequestBody @Valid RollBackReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return billCheckService.rollBack(req);
    }

}
